package com.starpl.mobile.android.monthunsae.november.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import com.starpl.mobile.android.monthunsae.november.R;
import com.starpl.mobile.android.monthunsae.november.domain.UserInfo;
import com.starpl.mobile.android.monthunsae.november.handler.CommunityListHandler;
import com.starpl.mobile.android.platform.common.base.BaseActivity;
import com.starpl.mobile.android.platform.common.base.BaseApplication;
import com.starpl.mobile.android.platform.component.StarplListView;

/**
 * 오늘의 운세 엑티비티를 띄웁니다.
 * 
 * @author 박우람
 * @since 2011.03.17
 */
public class UnsaeDailyActivity extends BaseActivity implements OnClickListener
{
	// 일상 키워드
	private static final int KEYWORD_IDX = 10000097;
	
	private ImageButton mIbViewDailyUnsae;
	private ImageButton mIbRefresh;
	private ImageButton mIbWrite;
	
	private CommunityListHandler mListHandler;
	private LinearLayout mLlCommunityLayout;
	
	/* (non-Javadoc)
	 * @see com.starpl.platform.common.base.BaseActivity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.unsae_daily_activity);
		
		mIbViewDailyUnsae = (ImageButton) findViewById(R.id.unsae_daily_activity_ib_daily_unsae);
		mIbRefresh = (ImageButton) findViewById(R.id.unsae_daily_activity_ib_refresh);
		mIbWrite = (ImageButton) findViewById(R.id.unsae_daily_activity_ib_write);
		mLlCommunityLayout = (LinearLayout) findViewById(R.id.unsae_daily_activity_ll_community);
		
		mIbViewDailyUnsae.setOnClickListener(this);
		mIbRefresh.setOnClickListener(this);
		mIbWrite.setOnClickListener(this);
		
		UserInfo userInfo = (UserInfo) BaseApplication.getGlobalPersistent("userInfo");
		mListHandler = new CommunityListHandler(this, userInfo.getUserId(), KEYWORD_IDX);
		StarplListView listView = new StarplListView(mListHandler);
		mLlCommunityLayout.addView(listView);
	}

	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View view)
	{
		switch(view.getId())
		{
		case R.id.unsae_daily_activity_ib_refresh:
			mListHandler.refresh();
			break;
		case R.id.unsae_daily_activity_ib_write:
			Bundle extras = new Bundle();
			extras.putInt("keywordIdx", KEYWORD_IDX);
			extras.putInt("type", WriteActivity.TYPE_POST);

			getNewActivity().setRequestCode(1).setTargetActivity(WriteActivity.class).setBundle(extras).show();
			break;
		case R.id.unsae_daily_activity_ib_daily_unsae:
			getNewActivity()
				.setTargetActivity(UnsaeDailyDetailActivity.class)
				.show();
			break;
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		if(resultCode == RESULT_OK)
		{
			mListHandler.refresh();
		}
	}
}
